<?php
/**
 * 记录每一个库存的分类属性值的表
 * String sku
 * String player
 * String brand
 */
class App_Model_StockAttrSku extends App_Model_Abstract
{
	public function init()
	{
		parent::init();
		$this->table = App_Db_Table::factory('StockAttrSku');
	}
	
	public function add($row)
	{
		return $this->table->insert($row);
	}
	
	public function update($row, $sku){
		$db = $this->table->getAdapter();
		$where = $db->quoteInto('sku = ?', $sku);
		
		return $this->table->update($row, $where);
	}
	
	public function getSku($player,$brand){
		$select = $this->table->select();
		if(!empty($player)){
			$select->where('player = ?',$player);
		}
		if(!empty($brand)){
			$select->where('brand = ?',$brand);
		}
		$select->from('stock_attr_sku','sku');
		return $this->table->fetchAll($select);
	}
	
	
	public function delete($sku)
	{
		$db = $this->table->getAdapter();
		$where = $db->quoteInto('sku = ?', $sku);
		
		$res = $this->table->delete($where);
		return $res;
	}

	
	public function getBySku($sku)
	{
		$db= $this->table->getAdapter();
		$where = $db->quoteInto('sku =?',$sku);
		$row = $this->table->fetchRow($where);
		return $row;
	}
	
}